import Vue from 'vue'
import App from './App'
import router from './router'
import '../src/assets/css/global.css'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import 'swiper/dist/css/swiper.min.css'
import 'swiper/dist/js/swiper.min'
import store from '../src/store/store.js'
import VueQuillEditor, {Quill} from 'vue-quill-editor'
import quillEmoji from 'quill-emoji'
// require styles
import 'quill-emoji/dist/quill-emoji.css'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
Quill.register('modules/quillEmoji', quillEmoji)
Vue.use(VueQuillEditor)
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.prototype.$http = axios
axios.defaults.baseURL = 'http://127.0.0.1:8000'
Vue.prototype.$bus = new Vue()
/* eslint-disable no-new */
let vue
setTimeout(() => {
  vue = new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
  })
}, 500)
axios.interceptors.request.use(config => {
  // console.log(config)
  NProgress.start()
  config.headers.Authorization = window.localStorage.getItem('token')
  return config
})
// 在response拦截器中，隐藏进度条 NProgress.done()
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
}, err => {
  if (err.response.status === 401) {
    vue.$message.error('登录已过期，请重新登录！')
    vue.$router.push('/login')
    vue.$bus.$emit('exit')
    window.sessionStorage.removeItem('token')
    window.sessionStorage.removeItem('userInfo')
  }
  NProgress.done()
  return Promise.reject(err)
})
